import {fetchHospitalRegistrationAPI} from "@/api/hospitalAPI/registrationAPI";
import {message} from "antd";
import {useEffect, useState} from "react";
import {RegistrationType} from "@/type/registrationType";

const useRegistration = (hoscode: string) => {
    // 医院挂号详情
    const [registration, setRegistration] = useState<RegistrationType>()

    // 加载状态
    const [loading, setLoading] = useState<boolean>(false)

    /**
     * @description 获取医院挂号详情的接口
     * */
    const fetchHospitalRegistration = async (): Promise<void> => {
        try {
            setLoading(true)
            const {data} = await fetchHospitalRegistrationAPI(hoscode as string)
            setRegistration(data)
        } catch (error: any) {
            message.error(error.message)
        } finally {
            setLoading(false)
        }
    }

    useEffect(() => {
        fetchHospitalRegistration()
    }, [])

    return {
        registration,
        loading
    }
}

export default useRegistration
